package com.my.chapter11;


import java.util.ArrayList;
import java.util.List;

public class practice3 {
    public static void main(String[] args) {
        Sequence.main(args);
    }
}

interface Selector {
    boolean end();
    Object current();
    void next();
}

class Sequence{
    private List<Object> items;
    private int next = 0;
    public Sequence(){
        items = new ArrayList<Object>();
    }
    public void add(Object x){
        items.add(x);
    }
    private class SequenceSelector implements Selector {
        private int i = 0;

        @Override
        public boolean end() {
            return i==items.size();
        }

        @Override
        public Object current() {
            return items.get(i);
        }

        @Override
        public void next() {
            if(i<items.size()){
                i++;
            }
        }

        public Sequence outer(){
            return Sequence.this;
        }
    }

    public Sequence.SequenceSelector selector(){
        return new Sequence.SequenceSelector();
    }

    public static void main(String[] args) {
        Sequence sequence = new Sequence();
        Sequence.SequenceSelector selector = sequence.selector();
        for(int i=0;i<10;i++){
            selector.outer().add(Integer.toString(i));
        }

        while(!selector.end()){
            System.out.print(selector.current() + " ");
            selector.next();
        }
    }
}
